<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class speciallist extends admin {
	function __construct() {
		parent::__construct();
		$this->dbs = pc_base::load_model('speciallist_model');
		$this->dbm = pc_base::load_model('maplist_model');
		$this->dbl = pc_base::load_model('linklist_model');
		$this->dbc = pc_base::load_model('category_model');
		$this->dbi = pc_base::load_model('indexcategory_model');
	}

	public function init() {
		$page = max(intval($_GET['page']), 1);
		switch($_GET['s']) {
			case '1':$infos = $this->dbs->listinfo('', 'weight DESC', $page,100);$type = "speciallist";break;
			case '2':$infos = $this->dbm->listinfo('', 'weight DESC', $page,100);$type = "maplist";break;
			case '3':$infos = $this->dbl->listinfo('', 'weight DESC', $page,100);$type = "linklist";break;
		}
		$big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=speciallist&c=speciallist&a=add&type='.$type.'\', title:\'添加栏目\', width:\'750\', height:\'200\'}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', "添加栏目");

		include $this->admin_tpl('list');
	}

	public function add() {
 		if(isset($_POST['dosubmit'])) {
 			$_POST['cat']['editTime'] = date('Y-m-d H:m:s',SYS_TIME);
 			if($_POST['type'] == 'speciallist'){
 				$this->dbs->insert($_POST['cat']);
 			}else if($_POST['type'] == 'maplist'){
 				$this->dbm->insert($_POST['cat']);
 			}else if($_POST['type'] == 'linklist'){
 				$this->dbl->insert($_POST['cat']);
 			}
			showmessage("添加栏目成功",HTTP_REFERER,'', 'add');
		}else {
			$show_validator = $show_scroll = $show_header = true;
			pc_base::load_sys_class('form', '', 0);
 			include $this->admin_tpl('add');
		}

	}

	public function edit(){
		if(isset($_POST['dosubmit'])){
			$_POST['cat']['editTime'] = date('Y-m-d H:m:s',SYS_TIME);
			if($_POST['type'] == 'speciallist'){
 				$this->dbs->update($_POST['cat'], '`id`=\''.$_POST['cat']['id'].'\'');
 			}else if($_POST['type'] == 'maplist'){
 				$this->dbm->update($_POST['cat'], '`id`=\''.$_POST['cat']['id'].'\'');
 			}else if($_POST['type'] == 'linklist'){
 				$this->dbl->update($_POST['cat'], '`id`=\''.$_POST['cat']['id'].'\'');
 			}
			showmessage('修改成功!', HTTP_REFERER, '', 'edit');
		}else{
			session_start();
			$_SESSION['catName'] = $_GET['catName'];
			$id = $_GET['id'];
			switch ($_GET['type']) {
					case 'speciallist':$data = $this->dbs->get_one('`id`=\''.$_GET['id'].'\'');break;
					case 'maplist':$data = $this->dbm->get_one('`id`=\''.$_GET['id'].'\'');break;
					case 'linklist':$data = $this->dbl->get_one('`id`=\''.$_GET['id'].'\'');break;
				}
			$show_validator = $show_scroll = $show_header = true;
			pc_base::load_sys_class('form', '', 0);
			include $this->admin_tpl('edit');
		}
	}

	public function delete(){
		switch ($_GET['type']) {
			case 'speciallist':$this->dbs->delete('`id`=\''.$_GET['id'].'\'');break;
			case 'maplist':$this->dbm->delete('`id`=\''.$_GET['id'].'\'');break;
			case 'linklist':$this->dbl->delete('`id`=\''.$_GET['id'].'\'');break;
		}
		showmessage('删除成功!', HTTP_REFERER);
	}
	
	public function check() {
		if($_GET['check'] == "edit"){
			session_start();
			if($_GET['catName'] != $_SESSION['catName']){
				switch ($_GET['type']) {
					case 'speciallist':$data = $this->dbs->get_one('`catName`=\''.$_GET['catName'].'\'');break;
					case 'maplist':$data = $this->dbm->get_one('`catName`=\''.$_GET['catName'].'\'');break;
					case 'linklist':$data = $this->dbl->get_one('`catName`=\''.$_GET['catName'].'\'');break;
				}
				if(!empty($data))
					exit('0');
			}
			exit('1');
		}else{
			if($_GET['type'] == "speciallist"){
				$data = $this->dbs->get_one('`catName`=\''.$_GET['catName'].'\'');
					if(!empty($data)){
						exit('0');
					}
				exit('1');
			}else{
				if($_GET['type'] == "maplist") {//判断相应栏目是否重名
					$datam = $this->dbm->get_one('`catName`=\''.$_GET['catName'].'\'');
						if(!empty($datam)){
							exit('0');
						}
				}
				else if($_GET['type'] == "linklist"){
					$datal = $this->dbl->get_one('`catName`=\''.$_GET['catName'].'\'');
						if(!empty($datal)){
							exit('0');
						}
				}//判断两个栏目和是否超过9
				$datam = $this->dbm->select('','*','','');
				$datal = $this->dbl->select('','*','','');
				if(count($datam)+count($datal)>9){
					exit('0');
				}
				exit('1');
			}
			
		}
		
	}

	public function indexcategoty(){
		$sql = '`type`=\'0\' and `catid`=`arrchildid` and `parentid`<>\'0\'';
		$lists = $this->dbc->select($sql, '*', '','');
		$infos = $this->dbi->select('', '*', '','');
		include $this->admin_tpl('newsList');
	}

	public function newsListUpdata(){
		for($i = 1;$i <= 6 ;$i++){
			$this->dbi->update(array('catId' => $_POST['s'.$i]), '`id`=\''.$i.'\'');
		}
		showmessage('修改成功!', HTTP_REFERER);
	}
}
?>